<hr/>
<form id="role_assign_form">            
    <label>Role Name</label>
    <div class="row">
        <div class="col-md-4">
            <?= shtmlform_select(application\system\model\auth\Role::getSelectData("title", "title", array('type' => ROLE_TYPE_END_USER)), null, array('class' => 'form-control role-title')) ?>
        </div>
        <div class="col-md-2">
            <input type="submit" class="btn btn-default" value="Assign"/>
        </div>
    </div>
</form>
<script>
    $('#role_assign_form').bind('submit', function(e){
        e.preventDefault();
        data = {
            role_title: $(this).find('.role-title').val(),
            user_id: <?= $this->object->user_id ?>
        };
        simbola.call.service("system", "auth", "roleAssign", {keys: data}, function(data){
            $('#system_authRole_list').simGrid_Reload();
        });
    });
    function revokeRole(role_title){
        data = {
            role_title: role_title,
            user_id: <?= $this->object->user_id ?>
        };
        simbola.call.service("system", "auth", "roleRevoke", {keys: data}, function(data){
            $('#system_authRole_list').simGrid_Reload();
        });
    }
</script>
<hr/>
<?php
$grid = new application\system\library\simgrid\WidgetSimGrid("system_authRole_list");
$grid->setTitle("Roles Assigned");
$grid->setTableCss('table-condensed table-hover');
$grid->setCondition(array('user_id = ?', $this->object->user_id));
$grid->setDataSource("system", "auth", "roleAssign");
$grid->setColumns(array(    	
	"role_title" => "Role",	
    "Actions",
));
$grid->setHiddenColumns(array('user_id'));
$grid->setActions(array(
    shtml_link("revoke", FALSE, array('class' => 'btn btn-default btn-xs btn-remove-role-assign', 'onClick' => '{revokeRole("{{role_title}}")}')),
));

echo $grid->getDisplayData();
?>